package com.shawn.example.mvvmdemo.login.repository

import com.jetpack.mvvm.lib.base.resp.BaseResp
import com.jetpack.mvvm.lib.base.resp.HttpResult
import com.jetpack.mvvm.lib.net.ServiceCreators
import com.jetpack.mvvm.lib.net.module.HttpApiResult
import com.shawn.example.mvvmdemo.login.model.LoginModel
import com.shawn.example.mvvmdemo.login.net.HttpLoginApiService
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@ActivityRetainedScoped
class RegisterLoginRemoteRepository @Inject constructor() {

    private val service = ServiceCreators.create(HttpLoginApiService::class.java)

    fun registerWanAndroid(
        username: String,
        pwd: String,
        rePwd: String
    ): Flow<HttpResult<LoginModel>> {
        return service.registerWanAndroid(username, pwd, rePwd)
    }

    fun loginWanAndroid(
        username: String,
        password: String
    ): Flow<HttpResult<LoginModel>> {
        return service.loginWanAndroid(username, password)
    }

    suspend fun loginWanApp(
        username: String,
        password: String
    ): HttpApiResult<LoginModel> {
        return service.loginWanApp(username, password)
    }

    fun logout(): Flow<BaseResp> {
        return service.logout()
    }

    companion object {
        val instance = SingleTonHolder.holder
    }

    private object SingleTonHolder {
        val holder = RegisterLoginRemoteRepository()
    }
}